/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.app.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.app.entity.OrderGoods2;
import com.thinkgem.jeesite.modules.app.service.OrderGoods2Service;

/**
 * 订单商品Controller
 * @author dby
 * @version 2020-07-14
 */
@Controller
@RequestMapping(value = "${adminPath}/app/orderGoods2")
public class OrderGoods2Controller extends BaseController {

	@Autowired
	private OrderGoods2Service orderGoods2Service;
	
	@ModelAttribute
	public OrderGoods2 get(@RequestParam(required=false) String id) {
		OrderGoods2 entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = orderGoods2Service.get(id);
		}
		if (entity == null){
			entity = new OrderGoods2();
		}
		return entity;
	}
	
	@RequiresPermissions("app:orderGoods2:view")
	@RequestMapping(value = {"list", ""})
	public String list(OrderGoods2 orderGoods2, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<OrderGoods2> page = orderGoods2Service.findPage(new Page<OrderGoods2>(request, response), orderGoods2); 
		model.addAttribute("page", page);
		return "modules/app/orderGoods2List";
	}

	@RequiresPermissions("app:orderGoods2:view")
	@RequestMapping(value = "form")
	public String form(OrderGoods2 orderGoods2, Model model) {
		model.addAttribute("orderGoods2", orderGoods2);
		return "modules/app/orderGoods2Form";
	}

	@RequiresPermissions("app:orderGoods2:edit")
	@RequestMapping(value = "save")
	public String save(OrderGoods2 orderGoods2, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, orderGoods2)){
			return form(orderGoods2, model);
		}
		orderGoods2Service.save(orderGoods2);
		addMessage(redirectAttributes, "保存订单商品成功");
		return "redirect:"+Global.getAdminPath()+"/app/orderGoods2/?repage";
	}
	
	@RequiresPermissions("app:orderGoods2:edit")
	@RequestMapping(value = "delete")
	public String delete(OrderGoods2 orderGoods2, RedirectAttributes redirectAttributes) {
		orderGoods2Service.delete(orderGoods2);
		addMessage(redirectAttributes, "删除订单商品成功");
		return "redirect:"+Global.getAdminPath()+"/app/orderGoods2/?repage";
	}

}